<template>
<div class="role-management views-container">
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link tag="span" to="/permission/roleManagementAdd">
                <el-button size="small" type="primary">添加角色</el-button>
            </router-link>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.roleManagement.key" :data="tableFormatData.roleManagement.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="name" label="角色名称" header-align="left" align="left">
                    <template slot-scope="scope">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="状态" header-align="left" align="left">
                    <template slot-scope="scope">
                        <el-switch :active-value="1" :inactive-value="0" @change="changeTableItem({store_role_id:scope.row.store_role_id},tableFormatData.roleManagement.change.is_use,{isWarning: scope.row.is_use === 0,warning:'是否关闭？',cancel:{msg:'已取消',val:{scope:scope,cancelStatus:{key:'is_use',val:0}}}})" v-model="scope.row.is_use"> </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="操作" header-align="left" align="left">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/permission/roleManagementAdd', query:{store_role_id:scope.row.store_role_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <!-- <div class="btn-line"></div>
              <router-link class="wlm-text" tag="span" to="/permission/roleManagementPermission">
                <el-button type="text">权限设置</el-button>
              </router-link> -->
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.store_role_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" :disabled="!hasTableData" true-label="1" false-label="0" v-model="tableFormatData.roleManagement.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.roleManagement.pagination.page" :page-sizes="tableFormatData.roleManagement.pagination.pagesizes" :page-size.sync="tableFormatData.roleManagement.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.roleManagement.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  staffRole,
  delStoreRoleInfo,
  roleEditStatus
} from '@/api/setting'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'RoleManagement',
  components: {

  },
  data() {
    return {
      tableFormatData: {
        current: 'roleManagement',
        roleManagement: {
          key: 'roleManagement',
          api: {
            getList: staffRole,
            delList: delStoreRoleInfo
          },
          tableData: [],
          files: {
            ids: [],
            redirect: 'store_role_id',
            checkall: '0',
            Recycle: '1'
          },
          change: {
            is_use: {
              key: 'is_use',
              api: roleEditStatus
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {

  }
}
</script>
